package com.css.apps.base.org.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.apps.base.log.model.LogConstant;
import com.css.apps.base.log.model.LogPart;
import com.css.apps.base.org.model.SSysOrgTree;
import com.css.core.configuration.Environment;
import com.css.db.query.QueryCache;
import com.css.db.query.TransactionCache;
import com.css.util.Ajax;
import com.css.util.Messages;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ModelDriven;

@SuppressWarnings("serial")
public class UpdCustomOrgTree extends AdminAction implements ModelDriven {
	
	private static Log log = LogFactory.getLog(UpdCustomOrgTree.class);
	private SSysOrgTree item;

	public UpdCustomOrgTree() {
		this.item = new SSysOrgTree();
	}

	@Override
	public Object getModel() {
		return item;
	}

	@Override
	protected String adminGo() {
		TransactionCache tx = null;
		try {
			SSysOrgTree oldItem = QueryCache.get(SSysOrgTree.class, item.getUuid());
			tx = new TransactionCache();
			oldItem.setDes(item.getDes());
			oldItem.setExp(item.getExp());
			oldItem.setSysId(item.getSysId());
			tx.update(oldItem);

			LogPart doclp = new LogPart();
			doclp.setRelObjId(item.getUuid());
			doclp.setRelObjType(SSysOrgTree.class.getName());
			doclp.setOpType(LogConstant.LOG_TYPE_MODIFY);
			doclp.setLogLevel(LogConstant.LOG_LEVEL_COMMON);
			doclp.save();
			tx.commit();
			result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS, Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			if (tx != null) {
				tx.rollback();
			}
			result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.exception"));
			return Action.ERROR;
		}
	}

	public SSysOrgTree getItem() {
		return item;
	}

	public void setItem(SSysOrgTree item) {
		this.item = item;
	}

}
